﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a background estimator.</summary>
	// Token: 0x0200001C RID: 28
	public class HBgEsti : HHandle
	{
		// Token: 0x060001AC RID: 428 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HBgEsti() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x060001AD RID: 429 RVA: 0x00009B7A File Offset: 0x00007D7A
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HBgEsti(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x060001AE RID: 430 RVA: 0x00009B89 File Offset: 0x00007D89
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HBgEsti(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x060001AF RID: 431 RVA: 0x00009B98 File Offset: 0x00007D98
		private void AssertSemType()
		{
			base.AssertSemType("bg_estimation");
		}

		// Token: 0x060001B0 RID: 432 RVA: 0x00009BA5 File Offset: 0x00007DA5
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HBgEsti obj)
		{
			obj = new HBgEsti(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x060001B1 RID: 433 RVA: 0x00009BC0 File Offset: 0x00007DC0
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HBgEsti[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HBgEsti[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HBgEsti(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Generate and initialize a data set for the background estimation.
		///   Modified instance represents: ID of the BgEsti data set.
		/// </summary>
		/// <param name="initializeImage">initialization image.</param>
		/// <param name="syspar1">1. system matrix parameter. Default: 0.7</param>
		/// <param name="syspar2">2. system matrix parameter. Default: 0.7</param>
		/// <param name="gainMode">Gain type. Default: "fixed"</param>
		/// <param name="gain1">Kalman gain / foreground adaptation time. Default: 0.002</param>
		/// <param name="gain2">Kalman gain / background adaptation time. Default: 0.02</param>
		/// <param name="adaptMode">Threshold adaptation. Default: "on"</param>
		/// <param name="minDiff">Foreground/background threshold. Default: 7.0</param>
		/// <param name="statNum">Number of statistic data sets. Default: 10</param>
		/// <param name="confidenceC">Confidence constant. Default: 3.25</param>
		/// <param name="timeC">Constant for decay time. Default: 15.0</param>
		// Token: 0x060001B2 RID: 434 RVA: 0x00009C30 File Offset: 0x00007E30
		public HBgEsti(HImage initializeImage, double syspar1, double syspar2, string gainMode, double gain1, double gain2, string adaptMode, double minDiff, int statNum, double confidenceC, double timeC)
		{
			IntPtr proc = HalconAPI.PreCall(2008);
			HalconAPI.Store(proc, 1, initializeImage);
			HalconAPI.StoreD(proc, 0, syspar1);
			HalconAPI.StoreD(proc, 1, syspar2);
			HalconAPI.StoreS(proc, 2, gainMode);
			HalconAPI.StoreD(proc, 3, gain1);
			HalconAPI.StoreD(proc, 4, gain2);
			HalconAPI.StoreS(proc, 5, adaptMode);
			HalconAPI.StoreD(proc, 6, minDiff);
			HalconAPI.StoreI(proc, 7, statNum);
			HalconAPI.StoreD(proc, 8, confidenceC);
			HalconAPI.StoreD(proc, 9, timeC);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(initializeImage);
		}

		/// <summary>
		///   Delete the background estimation data set.
		///   Instance represents: ID of the BgEsti data set.
		/// </summary>
		// Token: 0x060001B3 RID: 435 RVA: 0x00009CDC File Offset: 0x00007EDC
		public void CloseBgEsti()
		{
			IntPtr proc = HalconAPI.PreCall(2002);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Return the estimated background image.
		///   Instance represents: ID of the BgEsti data set.
		/// </summary>
		/// <returns>Estimated background image of the current data set.</returns>
		// Token: 0x060001B4 RID: 436 RVA: 0x00009D10 File Offset: 0x00007F10
		public HImage GiveBgEsti()
		{
			IntPtr proc = HalconAPI.PreCall(2003);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HImage result;
			num = HImage.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Change the estimated background image.
		///   Instance represents: ID of the BgEsti data set.
		/// </summary>
		/// <param name="presentImage">Current image.</param>
		/// <param name="upDateRegion">Region describing areas to change.</param>
		// Token: 0x060001B5 RID: 437 RVA: 0x00009D58 File Offset: 0x00007F58
		public void UpdateBgEsti(HImage presentImage, HRegion upDateRegion)
		{
			IntPtr proc = HalconAPI.PreCall(2004);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, presentImage);
			HalconAPI.Store(proc, 2, upDateRegion);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(presentImage);
			GC.KeepAlive(upDateRegion);
		}

		/// <summary>
		///   Estimate the background and return the foreground region.
		///   Instance represents: ID of the BgEsti data set.
		/// </summary>
		/// <param name="presentImage">Current image.</param>
		/// <returns>Region of the detected foreground.</returns>
		// Token: 0x060001B6 RID: 438 RVA: 0x00009DA8 File Offset: 0x00007FA8
		public HRegion RunBgEsti(HImage presentImage)
		{
			IntPtr proc = HalconAPI.PreCall(2005);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, presentImage);
			HalconAPI.InitOCT(proc, 1);
			int num = HalconAPI.CallProcedure(proc);
			HRegion result;
			num = HRegion.LoadNew(proc, 1, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(presentImage);
			return result;
		}

		/// <summary>
		///   Return the parameters of the data set.
		///   Instance represents: ID of the BgEsti data set.
		/// </summary>
		/// <param name="syspar2">2. system matrix parameter.</param>
		/// <param name="gainMode">Gain type.</param>
		/// <param name="gain1">Kalman gain / foreground adaptation time.</param>
		/// <param name="gain2">Kalman gain / background adaptation time.</param>
		/// <param name="adaptMode">Threshold adaptation.</param>
		/// <param name="minDiff">Foreground / background threshold.</param>
		/// <param name="statNum">Number of statistic data sets.</param>
		/// <param name="confidenceC">Confidence constant.</param>
		/// <param name="timeC">Constant for decay time.</param>
		/// <returns>1. system matrix parameter.</returns>
		// Token: 0x060001B7 RID: 439 RVA: 0x00009E00 File Offset: 0x00008000
		public double GetBgEstiParams(out double syspar2, out string gainMode, out double gain1, out double gain2, out string adaptMode, out double minDiff, out int statNum, out double confidenceC, out double timeC)
		{
			IntPtr proc = HalconAPI.PreCall(2006);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			HalconAPI.InitOCT(proc, 1);
			HalconAPI.InitOCT(proc, 2);
			HalconAPI.InitOCT(proc, 3);
			HalconAPI.InitOCT(proc, 4);
			HalconAPI.InitOCT(proc, 5);
			HalconAPI.InitOCT(proc, 6);
			HalconAPI.InitOCT(proc, 7);
			HalconAPI.InitOCT(proc, 8);
			HalconAPI.InitOCT(proc, 9);
			int num = HalconAPI.CallProcedure(proc);
			double result;
			num = HalconAPI.LoadD(proc, 0, num, out result);
			num = HalconAPI.LoadD(proc, 1, num, out syspar2);
			num = HalconAPI.LoadS(proc, 2, num, out gainMode);
			num = HalconAPI.LoadD(proc, 3, num, out gain1);
			num = HalconAPI.LoadD(proc, 4, num, out gain2);
			num = HalconAPI.LoadS(proc, 5, num, out adaptMode);
			num = HalconAPI.LoadD(proc, 6, num, out minDiff);
			num = HalconAPI.LoadI(proc, 7, num, out statNum);
			num = HalconAPI.LoadD(proc, 8, num, out confidenceC);
			num = HalconAPI.LoadD(proc, 9, num, out timeC);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Change the parameters of the data set.
		///   Instance represents: ID of the BgEsti data set.
		/// </summary>
		/// <param name="syspar1">1. system matrix parameter. Default: 0.7</param>
		/// <param name="syspar2">2. system matrix parameter. Default: 0.7</param>
		/// <param name="gainMode">Gain type. Default: "fixed"</param>
		/// <param name="gain1">Kalman gain / foreground adaptation time. Default: 0.002</param>
		/// <param name="gain2">Kalman gain / background adaptation time. Default: 0.02</param>
		/// <param name="adaptMode">Threshold adaptation. Default: "on"</param>
		/// <param name="minDiff">Foreground/background threshold. Default: 7.0</param>
		/// <param name="statNum">Number of statistic data sets. Default: 10</param>
		/// <param name="confidenceC">Confidence constant. Default: 3.25</param>
		/// <param name="timeC">Constant for decay time. Default: 15.0</param>
		// Token: 0x060001B8 RID: 440 RVA: 0x00009EF4 File Offset: 0x000080F4
		public void SetBgEstiParams(double syspar1, double syspar2, string gainMode, double gain1, double gain2, string adaptMode, double minDiff, int statNum, double confidenceC, double timeC)
		{
			IntPtr proc = HalconAPI.PreCall(2007);
			base.Store(proc, 0);
			HalconAPI.StoreD(proc, 1, syspar1);
			HalconAPI.StoreD(proc, 2, syspar2);
			HalconAPI.StoreS(proc, 3, gainMode);
			HalconAPI.StoreD(proc, 4, gain1);
			HalconAPI.StoreD(proc, 5, gain2);
			HalconAPI.StoreS(proc, 6, adaptMode);
			HalconAPI.StoreD(proc, 7, minDiff);
			HalconAPI.StoreI(proc, 8, statNum);
			HalconAPI.StoreD(proc, 9, confidenceC);
			HalconAPI.StoreD(proc, 10, timeC);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Generate and initialize a data set for the background estimation.
		///   Modified instance represents: ID of the BgEsti data set.
		/// </summary>
		/// <param name="initializeImage">initialization image.</param>
		/// <param name="syspar1">1. system matrix parameter. Default: 0.7</param>
		/// <param name="syspar2">2. system matrix parameter. Default: 0.7</param>
		/// <param name="gainMode">Gain type. Default: "fixed"</param>
		/// <param name="gain1">Kalman gain / foreground adaptation time. Default: 0.002</param>
		/// <param name="gain2">Kalman gain / background adaptation time. Default: 0.02</param>
		/// <param name="adaptMode">Threshold adaptation. Default: "on"</param>
		/// <param name="minDiff">Foreground/background threshold. Default: 7.0</param>
		/// <param name="statNum">Number of statistic data sets. Default: 10</param>
		/// <param name="confidenceC">Confidence constant. Default: 3.25</param>
		/// <param name="timeC">Constant for decay time. Default: 15.0</param>
		// Token: 0x060001B9 RID: 441 RVA: 0x00009F84 File Offset: 0x00008184
		public void CreateBgEsti(HImage initializeImage, double syspar1, double syspar2, string gainMode, double gain1, double gain2, string adaptMode, double minDiff, int statNum, double confidenceC, double timeC)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2008);
			HalconAPI.Store(proc, 1, initializeImage);
			HalconAPI.StoreD(proc, 0, syspar1);
			HalconAPI.StoreD(proc, 1, syspar2);
			HalconAPI.StoreS(proc, 2, gainMode);
			HalconAPI.StoreD(proc, 3, gain1);
			HalconAPI.StoreD(proc, 4, gain2);
			HalconAPI.StoreS(proc, 5, adaptMode);
			HalconAPI.StoreD(proc, 6, minDiff);
			HalconAPI.StoreI(proc, 7, statNum);
			HalconAPI.StoreD(proc, 8, confidenceC);
			HalconAPI.StoreD(proc, 9, timeC);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			GC.KeepAlive(initializeImage);
		}
	}
}
